﻿#ifndef SCROLLBAR_H
#define SCROLLBAR_H

#include <QWidget>
class QPainter;

#define  BACKGROUND_WIDTH  (10.0)

class ScrollBar : public QWidget
{
    Q_OBJECT
public:
    explicit ScrollBar(QWidget *parent = nullptr);
    void setCurrentIndex(const int& index);

protected:
    virtual void paintEvent(QPaintEvent *event) override;
    virtual void mousePressEvent(QMouseEvent *event) override;
    virtual void mouseMoveEvent(QMouseEvent *event) override;
    virtual void mouseReleaseEvent(QMouseEvent *event) override;

signals:
    // 0-25 26个字母
    void sigCurrentIndexChanged(const int& index);

private:
    void drawBackground(QPainter* painter);
    void drawIndex(QPainter* painter);
    void drawCurrendIndex(QPainter* painter, const float fDeltH);

private:
    int                 m_iCurrent = 0;
    bool                m_bDrawCurrentIndex = false;
    bool                m_bMousePressed     = false;
    QPoint              m_posPressed        = QPoint(0,0);

    QList<QRectF>       m_indexRectList;
    QRectF              m_backgroundRect;
};

#endif // SCROLLBAR_H
